package com.lenovo.manufacture.Activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.api.Api;
import com.lenovo.manufacture.bean.UserPeopleGetAll;

import org.json.JSONException;
import org.json.JSONObject;

import androidx.appcompat.app.AppCompatActivity;

public class RenShiActivity extends AppCompatActivity {

    private ListView lv_ren_shi;
    private RequestQueue queue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ren_shi);
        queue = Volley.newRequestQueue(this);
        initView();
        initData();
        lv_ren_shi.setAdapter(new ListAdapter());
    }

    private void initData() {
        JsonObjectRequest request = new JsonObjectRequest(1, Api.api + "/UserPeople/getAll", new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {

                try {
                    String message = jsonObject.getString("message");
                    if(message.equals("SUCCESS")){
                        UserPeopleGetAll json = new Gson().fromJson(jsonObject.toString(), UserPeopleGetAll.class);

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        },null);
        queue.add(request);
    }

    private void initView() {
        lv_ren_shi = (ListView) findViewById(R.id.lv_ren_shi);
    }

    class ListAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 5;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                ViewHolder holder = null;
            if (convertView == null) {
                convertView = View.inflate(RenShiActivity.this, R.layout.lv_ren_shi, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }


            return convertView;
        }

        class ViewHolder {
            public View rootView;
            public TextView tv_ren_name;
            public TextView tv_ren_engineer;

            public ViewHolder(View rootView) {
                this.rootView = rootView;
                this.tv_ren_name = (TextView) rootView.findViewById(R.id.tv_ren_name);
                this.tv_ren_engineer = (TextView) rootView.findViewById(R.id.tv_ren_engineer);
            }

        }
    }
}
